//
//  VIPController.swift
//  SeeFM_Swift
//
//  Created by CBCT_MBP on 2021/7/6.
//

import UIKit

class VIPController: SFBaseController {
    
    var data = [VipModel]()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        title = "视频解析"
        
        initBaseData()
        setupTableView()
        
        
        
    }
    
    func setupTableView() {
     
        let table = UITableView.init(frame: .zero, style: .plain)
        table.delegate = self
        table.dataSource = self
        table.tableFooterView = UIView()
        if #available(iOS 11.0, *) {
            table.contentInsetAdjustmentBehavior = .never
        } else {
        }
        table.backgroundColor = UIColor.white
        view.addSubview(table)
        table.snp.makeConstraints { (make) in
            make.edges.equalTo(UIEdgeInsets(top: Adapter.Screen.topHeight,left: 0,bottom: 0,right: 0))
        }
        
    }
    
    func initBaseData() {
        
        let icons = ["tx.jpeg",
                     "aiqiyi.jpeg",
                     "youku.jpeg",
                     "mangguo.jpeg",
                     "bilibili.jpeg"]
        
        let titles = ["腾讯视频",
                      "爱奇艺",
                      "优酷视频",
                      "芒果TV",
                      "BiliBili"]
        
        let linkUrls = ["https://v.qq.com",
                        "https://www.iqiyi.com",
                        "https://www.youku.com"
                        ,"https://www.mgtv.com",
                        "https://www.bilibili.com",]
        
        for i in 0..<icons.count {
            let model = VipModel.init()
            model.title = titles[i]
            model.linkUrl = linkUrls[i]
            model.logoIcon = icons[i]
            data.append(model)
        }
            
    }
    
}

extension VIPController: UITableViewDelegate,UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return data.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = VipCell.cellWithTableView(tableView: tableView) as! VipCell
        cell.configWithModel(model: data[indexPath.row])
        return cell
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let model = data[indexPath.row]
        let web = VIPWebController.init(model.linkUrl ?? "")
        self.navigationController?.pushViewController(web, animated: true)
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 70
    }
}

